package 剑指offer_leetcode;

/**
 * JZ3数组中重复的数字
 */
public class 剑指Offer03_数组中重复的数字 {
    public int findRepeatNumber(int[] nums) {
        for(int i=0;i<nums.length;i++){
            if(i==nums[i])
                continue;
            else{
                if(nums[i]==nums[nums[i]])
                    return nums[i];
                else{
                    swap(nums,i,nums[i]);
                    i--;
                }
            }
        }
        return -1;
    }

    void swap(int[] nums, int i, int j){
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
}
